package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.FormSetting;
import com.ruoyi.manage.service.IFormSettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 表单配置Controller
 * 
 * @author zww
 * @date 2025-07-14
 */
@Api
@RestController
@RequestMapping("/manage/formsetting")
public class FormSettingController extends BaseController
{
    @Autowired
    private IFormSettingService formSettingService;

    /**
     * 查询表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:formsetting:list')")
    @GetMapping("/list")
    public TableDataInfo list(FormSetting formSetting)
    {
        startPage();
        List<FormSetting> list = formSettingService.selectFormSettingList(formSetting);
        return getDataTable(list);
    }

    /**
     * 导出表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:formsetting:export')")
    @Log(title = "表单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FormSetting formSetting)
    {
        List<FormSetting> list = formSettingService.selectFormSettingList(formSetting);
        ExcelUtil<FormSetting> util = new ExcelUtil<FormSetting>(FormSetting.class);
        util.exportExcel(response, list, "表单配置数据");
    }

    /**
     * 获取表单配置详细信息
     */
    @ApiOperation("获取表单配置详细信息")
    @PreAuthorize("@ss.hasPermi('manage:formsetting:query')")
    @GetMapping(value = "/{formSettingId}")
    public AjaxResult getInfo(@PathVariable("formSettingId") Long formSettingId)
    {
        return success(formSettingService.selectFormSettingByFormSettingId(formSettingId));
    }

    /**
     * 新增表单配置
     */
    @PreAuthorize("@ss.hasPermi('manage:formsetting:add')")
    @Log(title = "表单配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FormSetting formSetting)
    {
        formSetting.setCreateBy(getUsername());
        return toAjax(formSettingService.insertFormSetting(formSetting));
    }

    /**
     * 修改表单配置
     */
    @PreAuthorize("@ss.hasPermi('manage:formsetting:edit')")
    @Log(title = "表单配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FormSetting formSetting)
    {
        formSetting.setUpdateBy(getUsername());
        return toAjax(formSettingService.updateFormSetting(formSetting));
    }

    /**
     * 删除表单配置
     */
    @PreAuthorize("@ss.hasPermi('manage:formsetting:remove')")
    @Log(title = "表单配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{formSettingIds}")
    public AjaxResult remove(@PathVariable Long[] formSettingIds)
    {
        return toAjax(formSettingService.deleteFormSettingByFormSettingIds(formSettingIds));
    }
}
